#include "BatchCheckOutResponseModel.h"



namespace MesModel {

BatchCheckOutResponseModel::BatchCheckOutResponseModel(QString factoryNo, QString transId, QDateTime eventTime, QString resultCode, QList<BatchCheckOutResponsePcuInfo> pcuInfo)
    :factoryNo(factoryNo),transId(transId),eventTime(eventTime),resultCode(resultCode),pcuInfo(pcuInfo)
{

}



BatchCheckOutResponsePcuInfo::BatchCheckOutResponsePcuInfo(QString locationNo, QString pcu, QString resultMsg)
    :locationNo(locationNo),pcu(pcu),resultMsg(resultMsg)
{

}



void BatchCheckOutResponsePcuInfo::fromJson(const QJsonObject &json)
{
    locationNo = json["locationNo"].toString();
    pcu = json["pcu"].toString();
    resultMsg = json["resultMsg"].toString();
}

QJsonObject BatchCheckOutResponsePcuInfo::toJson() const
{
    QJsonObject json;
    json["locationNo"] = locationNo;
    json["pcu"] = pcu;
    json["resultMsg"] = resultMsg;
    return json;
}

void BatchCheckOutResponseModel::fromJson(const QJsonObject &json)
{
    factoryNo = json["factoryNo"].toString();
    transId = json["transId"].toString();
    eventTime = QDateTime::fromString(json["eventTime"].toString());
    resultCode = json["resultCode"].toString();
    const QJsonArray pcu_info_array = json["pcuInfo"].toArray();
    for(const auto& item:pcu_info_array)
    {
        BatchCheckOutResponsePcuInfo pcu_info_item;
        pcu_info_item.fromJson(item.toObject());
        pcuInfo.append(pcu_info_item);
    }

}

QJsonObject BatchCheckOutResponseModel::toJson() const
{
    QJsonObject json;
    int randomNumber = QRandomGenerator::global()->bounded(10000,100000);
    json["factoryNo"]=factoryNo;
    json["transId"]=QString("%1%2").arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmssSSS")).arg(randomNumber);
    json["eventTime"]=eventTime.toString("yyyy-mm-dd hh:mm:ss");
    json["resultCode"]=resultCode;
    QJsonArray pcu_info_array;
    for(const auto& item:pcuInfo)
    {
        pcu_info_array.append(item.toJson());
    }
    json["pcuInfo"] = pcu_info_array;
    return json;

}

}
